package com.javawsl.exercise;

import com.sun.org.apache.xpath.internal.operations.Equals;

import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyThreadPool {

    public static void main(String[] args) {

        System.out.println("hello git!");
        System.out.println("hello git!");
        System.out.println("hello git!");
        System.out.println("master git!");
        System.out.println("hot-fix git!");
        System.out.println("hot-fix git!");


//        Objects.requireNonNull()
//        创建固定线程数的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(5);
//        创建只有一个线程的线程池
//        ExecutorService executorService = Executors.newSingleThreadExecutor();
//        创建弹性缓存线程池 该线程池中的线程空闲时间超过60秒时，会自动销毁
//        ExecutorService executorService = Executors.newCachedThreadPool();
//        创建定时线程池 可定时启动 延迟启动
//        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
//        创建多任务队列的线程池 创建多个任务队列，以此减少连接数 通过创建当前可用的cpu核数的线程，来并行的执行任务
//        ExecutorService executorService = Executors.newWorkStealingPool();

//        不要用executors创建线程池，因为有些参数，executors会使用默认值 使用者无法控制线程池创建的线程的参数，无法规避资源消耗的风险
//        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor();

//        ClassLoader classLoader = this.getClass().getClassLoader();
//        Class<?> aClass = classLoader.loadClass();

        String a = "abc";
        String b = "abc";
        String c = "AbC";
        String aaaaa = "abccc";

//        System.out.println("equals:"+a.equals(b));
//        System.out.println("大小写比较equals:"+a.equals(c));
//        System.out.println("equalsIgnoreCase:"+a.equalsIgnoreCase(b));
//        System.out.println("大小写比较equalsIgnoreCase："+a.equalsIgnoreCase(c));

//        char c1 = a.charAt(2);
//        System.out.println(c1);

//        System.out.println(a.substring(1));

//        System.out.println(a.toUpperCase(Locale.ROOT));
//        System.out.println(c.toLowerCase(Locale.ROOT));

        new MyThreadPool().equals(new MyThreadPool());
        boolean equals = a.equals(b);


        Lock lock = new ReentrantLock();

        try {
            lock.lock();//加锁
        } finally {
            lock.unlock();//释放锁
        }
    }
}
